<?php

namespace App\Providers\Jwt;

use Illuminate\Auth\EloquentUserProvider;
use Illuminate\Contracts\Auth\Authenticatable;

class AuthEloquentUserProvider extends EloquentUserProvider
{
    /**
     * Validate a user against the given credentials.
     *
     * @param  \Illuminate\Contracts\Auth\Authenticatable  $user
     * @param  array  $credentials
     * @return bool
     */
    public function validateCredentials(Authenticatable $user, array $credentials)
    {
        if (! count($credentials)){

            return false;
        }

        if (isset($credentials['id'])){

            return $credentials['id'] == $user->getAuthIdentifier();
        }

        if (isset($credentials['password'])){

            $plain = $credentials['password'];

            return $this->hasher->check($plain, $user->getAuthPassword());
        }

        return false;
    }
}
